# _*_ coding:utf-8 _*_
from django.db import models
from datetime import datetime

# Create your models here.


class Blog(models.Model):
    title = models.CharField(verbose_name=u'标题', max_length=100)
    desc = models.TextField(verbose_name=u'描述')
    content = models.TextField(verbose_name=u'文章内容')
    category = models.CharField(verbose_name=u'文章分类', max_length=30, default=u'未分类')
    tag = models.CharField(verbose_name=u'标签', max_length=30, default=u'')
    add_time = models.DateTimeField(verbose_name=u'添加时间', default=datetime.now)

    class Meta:
        verbose_name = u'博客'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title

    def get_fav_nums(self):
        return self.blogfavorite_set.all().count()

    def get_comment_nums(self):
        return self.comment_set.all().count()


class Comment(models.Model):
    article = models.ForeignKey(Blog, verbose_name=u'文章', null=True, blank=True)
    nick_name = models.CharField(verbose_name=u'昵称', max_length=50)
    email = models.EmailField(verbose_name=u'邮箱')
    content = models.TextField(verbose_name=u'评论内容')
    add_time = models.DateTimeField(verbose_name=u'评论时间', default=datetime.now)

    class Meta:
        verbose_name = u'评论'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.content


class BlogFavorite(models.Model):
    article = models.ForeignKey(Blog, verbose_name=u'文章', null=True, blank=True)
    fav_nums = models.IntegerField(default=0, verbose_name=u'点赞数')

    class Meta:
        verbose_name = u'收藏数'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.article


class MessageBoard(models.Model):
    name = models.CharField(verbose_name=u'用户名', max_length=30)
    email = models.EmailField(verbose_name=u'邮箱')
    address = models.CharField(verbose_name=u'地址', max_length=100)
    message = models.TextField(verbose_name=u'留言信息')

    class Meta:
        verbose_name = u'留言板'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.name
